#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

void Solve(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> b(n,vector<int>(m));
    int ones=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            string s;
            cin>>s;
            b[i][j]=s[j]-'0';
            ones+=b[i][j];
        }
    }
    if(ones==0||ones==1)cout<<"YES"<<endl;
    int row=0,col=0;
    //统计行全为1的数
    for(int i=0;i<n;i++){
        int sr=0;
        for(int j=0;j<m;j++){
            sr+=b[i][j];
        }
        if(sr==m)col++;
    }
    //统计列全为1的数
    for(int j=0;j<n;j++){
        int sc=0;
        for(int i=0;i<m;i++){
            sc+=b[i][j];
        }
        if(sc==n)row++;
    }
    if((row==2&&col==0)||(row==0&&col==2))cout<<"YES"<<endl;
    else if(row==1&&col==1){
        for(int i=0;i<n;i++){
            if(b[i][0]==0)continue;
            for(int j=0;j<m;j++){
                if(b[0][j]==0)continue;
                if(b[i][j]==0)cout<<"YES"<<endl;
            }
        }
    }
    else cout<<"NO"<<endl;
    
    return;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr); std::cout.tie(nullptr);
    int t;
    cin>>t;
    while(t--)Solve();

    return 0;
}